class Queue {
  items = {};
  lowCount = 0;
  count = 0;
  enqueue(item) {
    this.items[this.count] = item;
    this.count++;
  }
  dequeue() {
    if (this.isEmpty()) {
      return;
    }
    const dequeueItem = this.items[this.lowCount];
    delete this.items[this.lowCount];
    this.lowCount++;
    return dequeueItem;
  }
  front() {
    return this.items[this.lowCount];
  }
  isEmpty() {
    return this.size() === 0;
  }
  size() {
    return this.count - this.lowCount;
  }
  clear() {
    this.items = {};
    this.lowCount = 0;
    this.count = 0;
  }
}

/**
 * 击鼓传花游戏
 * @param {*} playerList 游戏玩家排好队的数组
 * @param {*} drumNum 固定击鼓的次数
 */
function gameJiGuChuanHua(playerList, drumNum) {
  const queue = new Queue();
  for (let i = 0; i < playerList.length; i++) {
    queue.enqueue(playerList[i]);
  }
  while (queue.size() > 1) {
    for (let i = 0; i < drumNum; i++) {
      queue.enqueue(queue.dequeue());
    }
    console.log(`${queue.dequeue()}淘汰了`);
  }
  return queue.dequeue();
}

console.log(gameJiGuChuanHua(['小灿1', '小灿2', '小灿3', '小灿4', '小灿5'], 5));